let isDone: boolean = true

let age: number = 12

let s: string = '123123'

let u: undefined = undefined

let n: null = null

let num: number = 12
num = null
num = undefined
// null 和undefind 是其他数据类型的子集。

let an: any = 123
an = '123'
an = true
an.name
an.getName()


let arrOfNumber: number[] = [1,2,'4']

// 元组
let arr: [number,string] = [1,'1']
arr.push('true')

// 接口
interface IPerson {
    readonly id:number;
    name: String;
    age?: Number; //表示该属性可有可无
}
// 约束类型
let fenzhilun: IPerson = {
    id:1,
    name: 'fengzhilun',
    age: 1
}
fenzhilun.name = '123123'

// 函数
function add(x: number, y: number, z?:number):number {
    if (typeof z === 'number') {
        return x+y+z
    } else {
        return x+y
    }
}

let add2 = (x: number, y: number, z?:number):number => {
    if (typeof z === 'number') {
        return x+y+z
    } else {
        return x+y
    }
}

let add3:(x:number, y:number, z?:number) => number = add2

// 接口里申明函数
interface Isum {
    (x:number, y:number, z?:number): number
}
let add4:Isum = add2

let result = add(1,2,3)

// 联合类型 两种类型的一种
let numberOrString: string|number = '123'
numberOrString.valueOf()

// 类型断言
let ABC= function(input: string|number):number {
    let a = input as string
    if (a.length) {
        return a.length
    } else {
        const num = input as number
        return num.toString().length
    }
}
function abc2(input: string|number):number {
   if (typeof input === 'string') {
       return input.length
   } else {
       return input.toString().length
   }
}